package com.evildog.workspace.log.application.controller;

import com.evildog.workspace.common.object.PageQuery;
import com.evildog.workspace.common.result.PagedResult;
import com.evildog.workspace.common.result.Result;
import com.evildog.workspace.common.result.ResultGenerator;
import com.evildog.workspace.dependencies.mybatis.util.QueryConditionUtils;
import com.evildog.workspace.log.application.bo.ExceptionLogBO;
import com.evildog.workspace.log.application.bo.ExceptionLogPageBO;
import com.evildog.workspace.log.application.convert.ExceptionLogConvert;
import com.evildog.workspace.log.application.model.ExceptionLogPageParam;
import com.evildog.workspace.log.application.service.ExceptionLogService;
import com.evildog.workspace.log.application.vo.ExceptionLogPageVO;
import com.evildog.workspace.log.application.vo.ExceptionLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * exceptionLog Controller
    异常日志
 * </p>
 *
 * @author evildog
 * @since 2020-08-29
 */
@RestController
@RequestMapping("/exception-logs")
@AllArgsConstructor
@Api(tags = "exceptionLog相关接口")
public class ExceptionLogController {

    private ExceptionLogService exceptionLogService;


    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(exceptionLogService.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> removeByIds(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(exceptionLogService.removeByIds(ids));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<ExceptionLogVO> getById(@PathVariable("id") Long id) {
        ExceptionLogBO exceptionLogBO = exceptionLogService.getDetailById(id);
        return ResultGenerator.success(ExceptionLogConvert.INSTANCE.convert(exceptionLogBO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<ExceptionLogPageVO>> getPageList(ExceptionLogPageParam exceptionLogPageParam, PageQuery query){
        PagedResult<ExceptionLogPageBO> exceptionLogPageBO = exceptionLogService.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(exceptionLogPageParam),
                        ExceptionLogConvert.INSTANCE.convert(exceptionLogPageParam));
        return ResultGenerator.success(ExceptionLogConvert.INSTANCE.convert(exceptionLogPageBO));
    }

}